package com.assistant.util;

import lombok.Data;

/**
 * MessageBodyWrapper
 *
 * @author yingjianhua
 */
@Data
public class MessageBodyWrapper<T> {
    private T data;
    private Boolean success;
    private String msg;
    private Integer code;
    private String total;

    public static <T> MessageBodyWrapper<T> success() {
        final MessageBodyWrapper<T> wrapper = new MessageBodyWrapper<>();
        wrapper.success = true;
        wrapper.code = 20000;
        return wrapper;
    }

    public static <T> MessageBodyWrapper<T> success(T data) {
        final MessageBodyWrapper<T> wrapper = new MessageBodyWrapper<>();
        wrapper.data = data;
        wrapper.success = true;
        wrapper.code = 20000;
        return wrapper;
    }

    public static <T> MessageBodyWrapper<T> failure(Integer code, String msg) {
        final MessageBodyWrapper<T> wrapper = new MessageBodyWrapper<>();
        wrapper.success = false;
        wrapper.code = code;
        wrapper.msg = msg;
        return wrapper;
    }

    public static <T> MessageBodyWrapper<T> failure(String msg) {
        final MessageBodyWrapper<T> wrapper = new MessageBodyWrapper<>();
        wrapper.success = false;
        wrapper.code = 40000;
        wrapper.msg = msg;
        return wrapper;
    }
}
